import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import NProgress from 'nprogress'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '小析のBlog'
    }
  },
  {
    path: '/guiDan',
    name: 'guiDan',
    meta: {
      title: "小析のblog-归档"
    },
    component: () => import('views/GuiDan.vue')
  },
  {
    path: '/qingDan',
    name: 'qingDan',
    meta: {
      title: "小析のblog-清单"
    },
    component: () => import('views/QingDan.vue')
  },
  {
    path: '/lettleSay',
    name: 'lettleSay',
    meta: {
      title: "小析のblog-聊天室"
    },
    component: () => import('views/LettleSay.vue')
  },
  {
    path: '/lmessage',
    meta: {
      title: "小析のblog-留言板"
    },
    component: () => import('views/Lmessage.vue')
  },
  {
    path: '/friendsHref',
    name: 'friendsHref',
    meta: {
      title: "小析のblog-友人帐"
    },
    component: () => import('views/FriendsHref.vue')
  },
  {
    path: '/about',
    name: 'about',
    meta: {
      title: "小析のblog-关于"
    },
    component: () => import('views/About.vue')
  },
  {
    path: '/backyard',
    name: 'backyard',
    meta: {
      title: "小析のblog-后院"
    },
    component: () => import('views/Backyard.vue')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('views/register/Register.vue'),
    meta: {
      title: '小析のBlog-注册'
    }
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('views/login/Login.vue'),
    meta: {
      title: '小析のBlog-登录'
    }
  },
  {
    path: "/account",
    name: "account",
    meta: {
      title: "小析のBlog-账户管理"
    },
    component: () => import('views/account/')
  },
  {
    path: '/:catchAll(.*)',
    name: '404',
    meta: {
      title: "小析のblog-404-页面未找到"
    },
    component: () => import('views/404/404.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from, next) => {
  //加载进度条启动
  NProgress.start();
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }

  next()
})

router.afterEach(() => {
  // 在即将进入新的页面组件前，关闭掉进度条
  NProgress.done()
})

//加载进度条配置
NProgress.configure({
  easing: 'ease',  // 动画方式    
  speed: 500,  // 递增进度条的速度    
  showSpinner: false, // 是否显示加载ico    
  trickleSpeed: 200, // 自动递增间隔    
  minimum: 0.3 // 初始化时的最小百分比
})

router.afterEach((to, from, next) => {
  window.scrollTo(0, 0);
});

export default router
